package com.example.magicapi.controller;

import com.example.magicapi.service.CustomService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author zk
 */
@Controller
public class CustomControllerView {
    @Resource
    private CustomService service;

    @RequestMapping(value = "custom/freemarker/index")
    public String index() {
        return "freemarker/index";
    }

    @GetMapping(value = "/")
    public String web(@RequestParam Map<String, Object> params, Model model) {
        List<Map<String, Object>> customList = service.getCustomList(params);
        model.addAttribute("resultList", customList);
        return "thymeleaf/index";
    }
    @GetMapping(value = "/template/cdStructuredCustom/customEmr")
    public String getCustomEmr(@RequestParam Map<String, Object> params, Model model) {
        List<Map<String, Object>> customList = service.getCustomList(params);
        model.addAttribute("resultList", customList);
        return "thymeleaf/customEmrDesign";
    }

    @RequestMapping(value = "custom/thymeleaf/customList")
    public String getCustomList(@RequestParam Map<String, Object> params, Model model) {
        List<Map<String, Object>> customList = service.getCustomList(params);
        model.addAttribute("resultList", customList);
        return "thymeleaf/customList";
    }
    @GetMapping(value = "/template/cdStructuredCustom/customEmrEdit")
    public String customEmrEdit(@RequestParam Map<String, Object> params, Model model) {
        List<Map<String, Object>> customList = service.getCustomList(params);
        model.addAttribute("resultList", customList);
        return "thymeleaf/customEmrEdit";
    }

    @RequestMapping(value = "/customPage/customPageIndex", method = RequestMethod.GET)
    public String customPageIndex(@RequestParam Map<String, Object> params, Model model, HttpServletRequest req)throws Exception {
        params.put("del","0");
        params.put("menuHref","/customPage/customPageIndex?menuShortName="+params.get("menuShortName"));
        model.addAllAttributes(service.findByCondition(params).getResults());
//        model.addAllAttributes(getUserAndPatientInfo(params,req));
        model.addAllAttributes(params);
        return "thymeleaf/customPage";
    }
}
